package com.neu.yth.nepBackend.statistics.controller;

import com.neu.yth.nepBackend.entity.Statistics;
import com.neu.yth.nepBackend.statistics.service.IStatisticsService;
import com.neu.yth.nepBackend.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 空气质量监测数据统计表 前端控制器
 * </p>
 *
 * @author YTH
 * @since 2024-05-31
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {
    @Autowired
    IStatisticsService statisticsService;

    /**
     * 根据afId查询
     *
     * @param afId
     * @return
     */
    @GetMapping("select/ByAfId")
    public Result selectById(@RequestParam("afId") Integer afId) {
        return statisticsService.selectByAfId(afId);
    }

    /**
     * 查询本网格员所有反馈信息
     *
     * @return
     */
    @GetMapping("select/all")
    public Result selectAll(@Param("gmId") Integer gmId) {
        return statisticsService.selectAll(gmId);
    }


    /**
     * 提交反馈信息
     *
     * @param statistics
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody Statistics statistics, @RequestHeader(value = "Authorization") String token) {
        return statisticsService.submit(statistics, token);
    }


    @PutMapping("/update")
    public Result update(@RequestBody Statistics statistics) {
        return statisticsService.updateStatisticsById(statistics);
    }
}
